package cn.com.backstage.controller.base;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiU_match_works;

import cn.com.api.service.ApiU_match_worksService;

import cn.com.util.*;


public class U_match_worksBaseController {

	private static Logger logger = Logger.getLogger(U_match_worksBaseController.class);
	
	@Autowired
	private ApiU_match_worksService apiU_match_worksService;
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "u_match_works-list")
	public ModelAndView u_match_works_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_match_works_list.jsp");
		
		List<ApiU_match_works> u_match_workss = apiU_match_worksService.findU_match_workss();
		mv.addObject("u_match_workss", u_match_workss);
		
		return mv;
	}
	
	/**
	 * 进入新增或者编辑页面
	 * @return
	 */
	@RequestMapping(value = "u_match_works-add-pre")
	public ModelAndView u_match_works_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/u_match_works_add.jsp");
		//
		if(request.getParameter("id")!=null){
			String id = request.getParameter("id");
			ApiU_match_works u_match_works = apiU_match_worksService.findU_match_worksById(Integer.valueOf(id));
			mv.addObject("u_match_works",u_match_works);
		}
		return mv;
	}

	/**
	 *新增或者编辑
	 * @return
	 */
	@RequestMapping(value = "u_match_works-add")
	public void u_match_works_add(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String works_id = request.getParameter("works_id");
		String match_id = request.getParameter("match_id");
		String join_name = request.getParameter("join_name");
		String join_card_id = request.getParameter("join_card_id");
		String sex = request.getParameter("sex");
		String mobile = request.getParameter("mobile");
		String province = request.getParameter("province");
		String city = request.getParameter("city");
		String area = request.getParameter("area");
		String address = request.getParameter("address");
		String works_name = request.getParameter("works_name");
		String works_desc = request.getParameter("works_desc");
		String works_type = request.getParameter("works_type");
		String works_url = request.getParameter("works_url");
		String vedio_url = request.getParameter("vedio_url");
		String status = request.getParameter("status");
		String reject_reason = request.getParameter("reject_reason");
		String ext1 = request.getParameter("ext1");
		String ext2 = request.getParameter("ext2");
		String ext3 = request.getParameter("ext3");
		String ext4 = request.getParameter("ext4");
		String ext5 = request.getParameter("ext5");
		String audit_by = request.getParameter("audit_by");
		String audit_time = request.getParameter("audit_time");
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		//add
		if(id==null || (id.trim()).equals("")){
			ApiU_match_works u_match_works = new ApiU_match_works();
            /*
		    u_match_works.setWorks_id(works_id);
		    u_match_works.setMatch_id(match_id);
		    u_match_works.setJoin_name(join_name);
		    u_match_works.setJoin_card_id(join_card_id);
		    u_match_works.setSex(sex);
		    u_match_works.setMobile(mobile);
		    u_match_works.setProvince(province);
		    u_match_works.setCity(city);
		    u_match_works.setArea(area);
		    u_match_works.setAddress(address);
		    u_match_works.setWorks_name(works_name);
		    u_match_works.setWorks_desc(works_desc);
		    u_match_works.setWorks_type(works_type);
		    u_match_works.setWorks_url(works_url);
		    u_match_works.setVedio_url(vedio_url);
		    u_match_works.setStatus(status);
		    u_match_works.setReject_reason(reject_reason);
		    u_match_works.setExt1(ext1);
		    u_match_works.setExt2(ext2);
		    u_match_works.setExt3(ext3);
		    u_match_works.setExt4(ext4);
		    u_match_works.setExt5(ext5);
		    u_match_works.setAudit_by(audit_by);
		    u_match_works.setAudit_time(audit_time);
	        */
			apiU_match_worksService.insertU_match_works(u_match_works);
		}
		//edit
		else{
			ApiU_match_works u_match_works = apiU_match_worksService.findU_match_worksById(Integer.valueOf(id));
	        /*
		    u_match_works.setWorks_id(works_id);
		    u_match_works.setMatch_id(match_id);
		    u_match_works.setJoin_name(join_name);
		    u_match_works.setJoin_card_id(join_card_id);
		    u_match_works.setSex(sex);
		    u_match_works.setMobile(mobile);
		    u_match_works.setProvince(province);
		    u_match_works.setCity(city);
		    u_match_works.setArea(area);
		    u_match_works.setAddress(address);
		    u_match_works.setWorks_name(works_name);
		    u_match_works.setWorks_desc(works_desc);
		    u_match_works.setWorks_type(works_type);
		    u_match_works.setWorks_url(works_url);
		    u_match_works.setVedio_url(vedio_url);
		    u_match_works.setStatus(status);
		    u_match_works.setReject_reason(reject_reason);
		    u_match_works.setExt1(ext1);
		    u_match_works.setExt2(ext2);
		    u_match_works.setExt3(ext3);
		    u_match_works.setExt4(ext4);
		    u_match_works.setExt5(ext5);
		    u_match_works.setAudit_by(audit_by);
		    u_match_works.setAudit_time(audit_time);
			*/
			apiU_match_worksService.updateU_match_works(u_match_works);
		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
        JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
	/**
	 *删除
	 * @return
	 */
	@RequestMapping(value = "u_match_works-delete")
	public void u_match_works_delete(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		
		//delete
		int ret_i =	apiU_match_worksService.deleteU_match_works(Integer.valueOf(id));
		
		//
		if(ret_i > 0){
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
}



